import React from "react";
import { useSelector, useDispatch } from "react-redux";
import { adminSlice } from "../../redux/redux";

export default function Mine() {
  const dispatch = useDispatch();
  const { aa } = adminSlice.actions;
  const ke = () => {
    dispatch(aa());
  };

  const data = useSelector((state) => state.adminSlice);
  const { admin } = data;
  const newUser = {
    name: "注册的新账号",
    phone: "因为后台数据原因",
    loginId: "新账号",
    photo: "暂不支持",
    role: "修改密码",
  };
  if (admin) {
    var { name, phone, loginId, photo, role } = admin;
  } else {
    var { name, phone, loginId, photo, role } = newUser;
  }

  return (
    <div className="mine">
      <img
        style={{ width: "300px" }}
        src={
          "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F92e26652-7b4b-4c39-a6ae-d5337976e9d9%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1682323203&t=fe22a01b8a980ec4c356d186f7721f33"
        }
      ></img>
      <p>账号：{loginId} </p>
      <p>姓名：{name} </p>
      <p>电话：{phone} </p>
      <p>照片：{photo} </p>
      <p>角色：{role} </p>
      <button onClick={ke} hidden={admin ? false : true}>
        尝试修改redux数据
      </button>
    </div>
  );
}
